﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyThirty_EighthWPFDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation dAnimation = new DoubleAnimation();
            dAnimation.From = ellipse.ActualWidth;
            dAnimation.To = Height / 2;
            dAnimation.Duration = TimeSpan.FromSeconds(1);
            //dAnimation.BeginTime = TimeSpan.FromSeconds(3);   //设置动画延时三秒
            dAnimation.SpeedRatio = 2;                          //动画速度默认为1，如果设为2，则为2倍速度，那么事件只需要0.5s，跟Duration对应
            //dAnimation.AutoReverse = true;
            dAnimation.AccelerationRatio = 0.3;             //前30%秒加速，后面不变
            dAnimation.DecelerationRatio = 0.3;             //接着后30%秒减速，再后面不变
            dAnimation.RepeatBehavior = new RepeatBehavior(2); //重复2次
            ellipse.BeginAnimation(Ellipse.WidthProperty, dAnimation);
            ellipse.BeginAnimation(Ellipse.HeightProperty, dAnimation);
        }
    }
}
